import { useState, useEffect } from 'react'
import { fetchChannelAPI, ChannelItem } from '@/apis/list'

function useTabs() {
  const [channels, setChannels] = useState<ChannelItem[]>([])

  useEffect(() => {
    const getChannel = async () => {
      try {
        const res = await fetchChannelAPI()
        setChannels(res.data.data.channels)
      } catch (error) {
        console.error('Error fetching channel:', error);
        throw new Error('fetch channel error: Failed to fetch data from API');
      }
    }
    getChannel()
  }, [])
  return { channels }
}

export { useTabs }